/**
 * Created by wanghuan on 2017/4/9.
 */

/*==========================pto 相关接口==============================*/

import Ajax from '../../apiAjax';

export  default {
  state:{
    ptoPreview:[],//pto列表,
    ptoTypeList:[], //setting 界面
    ptoList:[], //pto

  },
  mutations:{
    setCommonStateData(state,{key,data}){
      state[key] = data;
    }
  },
  actions:{
    getPtoPreview({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/pto/preview',
          data:paramData,
          type:'get',
          success:function (data) {
            commit('setCommonStateData',{key:'ptoPreview',data:data.data});
            resolve(data);
          }
        })
      })
    },
    getPtoList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/pto/list',
          data:paramData,
          type:'get',
          success:function (data) {
            commit('setCommonStateData',{key:'ptoList',data:data.data});
            resolve(data);
          }
        })
      })
    },
    /**
     * 保存pto
     * @param commit
     * @param paramData
     * @returns {Promise}
     */
    savePtoType({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/savePtoType',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     * pto 授权
     * @param commit
     * @param paramData
     * 员工ID	employeeIds	string	用逗号分隔,,0则是所有员工
       pto类型Id 	ptoTypeId	number
       权限类别	isAllEmployee	Integer 	0:公司所有员工都有权限1：部分员工有权限2: 所有员工都没权限
     * @returns {Promise}
     */
    authorizePto({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/authorizePto',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     * 新增PTO规则
     * @param commit
     * @param paramData
     * @returns {Promise}
     */
    addPtoRule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/newPtoRule',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     * 查询pto 规则
     * @param commit
     * @param paramData
     * @returns {Promise}
     */
    getPtoRule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/getPtoRule',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     * 直接添加或减少假日时间
     * @param commit
     * @param paramData
     * @returns {Promise}
     */
    addAccrualLedger({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/addAccrualLedger',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    getPtoTypeList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/getPtoTypeList',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'ptoTypeList',data:data.data});
            resolve(data);
          }
        })
      })
    },
    deletePtoType({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/delPtoType',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    setPtoTypeTrackAccrual({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/setPtoTypeTrackAccural',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    applyPto({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/pto/apply',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    getPtoTypeEmployeesList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/pto/getPtoTypeEmployeesList',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },

  },
  getters: {
    ptoPreview:(state, getters)=> {
      return state.ptoPreview;
    },
    ptoTypeList:(state, getters)=> {
      return state.ptoTypeList;
    },
    ptoList:(state, getters)=> {
      return state.ptoList;
    },
  }
}
